/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.GUI.MenuMain;

import edu.nii.qlks.ControlLayer.LoaiTaiKhoanControl;
import edu.nii.qlks.ControlLayer.TaiKhoanControl;
import edu.nii.qlks.DataTransferObject.TaiKhoanInfo;
import edu.nii.qlks.GUI.Render.TableColor;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author MARS_NHO
 */
public class jfrm_ThemTaiKhoan extends javax.swing.JInternalFrame {
    TaiKhoanControl taiKhoanCT;
    TaiKhoanInfo taiKhoanInfo;
    LoaiTaiKhoanControl loaiTaiKhoanCT;
    
    private static Vector tableRecords = new Vector();
    private static Vector tableTitle = new Vector();
    
    boolean isThem = false;
    boolean isSua = false;
    boolean isXoa = false;
    /**
     * Creates new form jfrm_ThemTaiKhoan
     */
    public jfrm_ThemTaiKhoan() {
        initComponents();
        
        taiKhoanCT = new TaiKhoanControl();
        taiKhoanInfo = new TaiKhoanInfo();
        loaiTaiKhoanCT = new LoaiTaiKhoanControl();
        
        tableTitle.removeAllElements();
        tableTitle.add("STT");
        tableTitle.add("Tên tài khoản");
        tableTitle.add("Loại tài khoản");
        tableTitle.add("Mật khẩu");
        jXTable_TaiKhoan.setModel(new DefaultTableModel(tableRecords, tableTitle));
        jXTable_TaiKhoan.getColumnModel().getColumn(0).setPreferredWidth(50);
        jXTable_TaiKhoan.getColumnModel().getColumn(1).setPreferredWidth(100);
        jXTable_TaiKhoan.getColumnModel().getColumn(2).setPreferredWidth(100);
        jXTable_TaiKhoan.getColumnModel().getColumn(3).setPreferredWidth(50);
        
        Load_Table();
        LoadData_Table();
        Load_MaLoaiTaiKhoan();
    }
    
    public void Load_Table(){
        TableColor color = new TableColor();
        
        
        
        jXTable_TaiKhoan.setDefaultRenderer(Object.class, color);
        
        //jXTable_TaiKhoan.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED));
    }
    
    public void LoadData_Table(){
        tableRecords.removeAllElements();
        try {
            Vector vt = taiKhoanCT.LayDS_TenLoaiTaiKhoan();
            if (vt.size() > 0){
                for (int i = 0; i < vt.size(); i++){
                    Vector vt_row = (Vector)vt.get(i);
                    Vector vt_dis = new Vector();
                    int index = i;
                    vt_dis.add(index+1);
                    vt_dis.add(vt_row.get(1).toString().trim());
                    vt_dis.add(vt_row.get(3).toString().trim());
                    vt_dis.add(vt_row.get(4).toString().trim());
                    
                    tableRecords.add(vt_dis);
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        jXTable_TaiKhoan.setModel(new DefaultTableModel(tableRecords, tableTitle));
    }
    
    public void Load_MaLoaiTaiKhoan(){
        try {
            Vector vt = loaiTaiKhoanCT.LayDS();
            if (vt.size() > 0){
                for (int i = 0; i < vt.size(); i++){
                    Vector vt_row = (Vector)vt.get(i);
                    jComboBox_MaTaiKhoan.addItem(vt_row.get(1).toString());
                }
                
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    public void ThemTaiKhoan(){
        if (jXTextField_TenTaiKhoan.getText().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng nhập tên tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jXTextField_TenTaiKhoan.requestFocus();
            return;
        }
        if (jComboBox_MaTaiKhoan.getSelectedItem().toString().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn mã loại tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jComboBox_MaTaiKhoan.requestFocus();
            return;
        }
        if (new String(jPasswordField_MatKhau.getPassword()).equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng nhập mật khẩu tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jPasswordField_MatKhau.requestFocus();
            return;
        }
        
        Vector vt = new Vector();
        String str = "";
        try {
            vt = taiKhoanCT.LayDS();
            if (vt.size() > 0){
                for (int i = 0; i < vt.size(); i++){
                    Vector vt_row = (Vector)vt.get(i);
                    if (jXTextField_TenTaiKhoan.getText().equals(vt_row.get(1).toString().trim())){
                        JOptionPane.showMessageDialog(rootPane, "Tài khoản đã được lập!", "Lỗi", JOptionPane.ERROR_MESSAGE);
                        jXTextField_TenTaiKhoan.requestFocus();
                        jPasswordField_MatKhau.setText("");
                        return;
                    }
                }
                Vector vt_row = (Vector)vt.get(vt.size() - 1);
                str = vt_row.get(0).toString().trim();
                taiKhoanInfo.setMaTaiKhoan(taiKhoanCT.TaoMaTuDong(str, 3));
            }
            else{
                taiKhoanInfo.setMaTaiKhoan(taiKhoanCT.TaoMaTuDong("MTK000", 3));
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        taiKhoanInfo.setTenTaiKhoan(jXTextField_TenTaiKhoan.getText().trim());
        taiKhoanInfo.setMatKhau(new String(jPasswordField_MatKhau.getPassword()));
        try {
            vt = loaiTaiKhoanCT.LayDS_TenLoaiTaiKhoan(jComboBox_MaTaiKhoan.getSelectedItem().toString().trim());
            if (vt.size() > 0){
                Vector vt_row = (Vector)vt.get(0);
                taiKhoanInfo.setMaLoaiTaiKhoan(vt_row.get(0).toString().trim());
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            taiKhoanCT.Insert(taiKhoanInfo);
            JOptionPane.showMessageDialog(rootPane, "Thêm tài khoản thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            jXButton_Them.setEnabled(false);
            jXTextField_TenTaiKhoan.setEnabled(false);
            jPasswordField_MatKhau.setEnabled(false);
            jComboBox_MaTaiKhoan.setEnabled(false);
            LoadData_Table();
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(rootPane, "Thêm mới tài khoản không thành công!", "Lỗi", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    
    public void SuaTaiKhoan(){
        if (jXTextField_TenTaiKhoan.getText().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng nhập tên tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jXTextField_TenTaiKhoan.requestFocus();
            return;
        }
        if (jComboBox_MaTaiKhoan.getSelectedItem().toString().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn mã loại tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jComboBox_MaTaiKhoan.requestFocus();
            return;
        }
        if (new String(jPasswordField_MatKhau.getPassword()).equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng nhập mật khẩu tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jPasswordField_MatKhau.requestFocus();
            return;
        }
        
        Vector vt = new Vector();
        String str = "";
        try {
            vt = taiKhoanCT.Lay_MaTaiKhoan(jXTextField_TenTaiKhoan.getText());
            if (vt.size() > 0){
                Vector vt_row = (Vector)vt.get(0);
                taiKhoanInfo.setMaTaiKhoan(vt_row.get(0).toString().trim());
                System.out.println("ma tai khoan: " + taiKhoanInfo.getMaTaiKhoan());
                taiKhoanInfo.setTenTaiKhoan(jXTextField_TenTaiKhoan.getText());
                System.out.println("ten tai khoan: " + taiKhoanInfo.getTenTaiKhoan());
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        taiKhoanInfo.setMatKhau(new String(jPasswordField_MatKhau.getPassword()));
        System.out.println("mat khau tai khoan: " + taiKhoanInfo.getMatKhau());
        try {
            vt = loaiTaiKhoanCT.LayDS_TenLoaiTaiKhoan(jComboBox_MaTaiKhoan.getSelectedItem().toString().trim());
            if (vt.size() > 0){
                Vector vt_row = (Vector)vt.get(0);
                taiKhoanInfo.setMaLoaiTaiKhoan(vt_row.get(0).toString().trim());
                System.out.println("ma loai tai khoan: " + taiKhoanInfo.getMaLoaiTaiKhoan());
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //UPDATE TAI KHOAN
        try {
            taiKhoanCT.Update(taiKhoanInfo);
            JOptionPane.showMessageDialog(rootPane, "Chỉnh sửa tài khoản thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            LoadData_Table();
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(rootPane, "Chỉnh sửa tài khoản không thành công!", "Lỗi", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    public void XoaTaiKhoan(){
        if (jXTextField_TenTaiKhoan.getText().equals("")){
            JOptionPane.showMessageDialog(rootPane, "Vui lòng nhập tên tài khoản", "Lỗi", JOptionPane.ERROR_MESSAGE);
            jXTextField_TenTaiKhoan.requestFocus();
            return;
        }
        
        Vector vt = new Vector();
        String str = "";
        try {
            vt = taiKhoanCT.Lay_MaTaiKhoan(jXTextField_TenTaiKhoan.getText());
            if (vt.size() > 0){
                Vector vt_row = (Vector)vt.get(0);
                taiKhoanInfo.setMaTaiKhoan(vt_row.get(0).toString().trim());
            }
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        //DELETE TAI KHOAN
        try {
            taiKhoanCT.Delete(taiKhoanInfo);
            JOptionPane.showMessageDialog(rootPane, "Xóa tài khoản thành công!", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
            LoadData_Table();
        } catch (Exception ex) {
            Logger.getLogger(jfrm_ThemTaiKhoan.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(rootPane, "Xóa tài khoản không thành công!", "Lỗi", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel_Nen = new org.jdesktop.swingx.JXPanel();
        jXLabel_TieuDe = new org.jdesktop.swingx.JXLabel();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jComboBox_MaTaiKhoan = new javax.swing.JComboBox();
        jXLabel_MaTaiKhoan = new org.jdesktop.swingx.JXLabel();
        jXLabel_TenTaiKhoan = new org.jdesktop.swingx.JXLabel();
        jXTextField_TenTaiKhoan = new org.jdesktop.swingx.JXTextField();
        jXLabel_MatKhau = new org.jdesktop.swingx.JXLabel();
        jPasswordField_MatKhau = new javax.swing.JPasswordField();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTable_TaiKhoan = new org.jdesktop.swingx.JXTable();
        jXButton_Thoat = new org.jdesktop.swingx.JXButton();
        jXButton_Them = new org.jdesktop.swingx.JXButton();
        jXButton_LamMoi = new org.jdesktop.swingx.JXButton();
        jXButton_Xoa = new org.jdesktop.swingx.JXButton();
        jXButton_Sua = new org.jdesktop.swingx.JXButton();

        jXPanel_Nen.setBackground(new java.awt.Color(255, 255, 255));

        jXLabel_TieuDe.setText("THÊM TÀI KHOẢN");
        jXLabel_TieuDe.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

        jXPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jXPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin tài khoản"));

        jXLabel_MaTaiKhoan.setText("Mã tài khoản");
        jXLabel_MaTaiKhoan.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jXLabel_TenTaiKhoan.setText("Tên tài khoản");
        jXLabel_TenTaiKhoan.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jXTextField_TenTaiKhoan.setEnabled(false);

        jXLabel_MatKhau.setText("Mật khẩu");
        jXLabel_MatKhau.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jPasswordField_MatKhau.setEnabled(false);
        jPasswordField_MatKhau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPasswordField_MatKhauActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel1Layout.createSequentialGroup()
                        .addComponent(jXLabel_TenTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(46, 46, 46))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel1Layout.createSequentialGroup()
                        .addComponent(jXLabel_MatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(72, 72, 72)))
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPasswordField_MatKhau)
                    .addComponent(jXTextField_TenTaiKhoan, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                .addComponent(jXLabel_MaTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jComboBox_MaTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel_TenTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXTextField_TenTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel_MaTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_MaTaiKhoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel_MatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPasswordField_MatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jXPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jXPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách tài khoản"));
        jXPanel2.setLayout(new java.awt.BorderLayout());

        jXTable_TaiKhoan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jXTable_TaiKhoan.setEditable(false);
        jXTable_TaiKhoan.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXTable_TaiKhoan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jXTable_TaiKhoanMouseClicked(evt);
            }
        });
        jXTable_TaiKhoan.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jXTable_TaiKhoanMouseMoved(evt);
            }
        });
        jScrollPane2.setViewportView(jXTable_TaiKhoan);

        jXPanel2.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jXButton_Thoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit_16.png"))); // NOI18N
        jXButton_Thoat.setText("Thoát");
        jXButton_Thoat.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_Thoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_ThoatActionPerformed(evt);
            }
        });

        jXButton_Them.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N
        jXButton_Them.setText("Thêm");
        jXButton_Them.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_Them.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_ThemActionPerformed(evt);
            }
        });

        jXButton_LamMoi.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/refresh.png"))); // NOI18N
        jXButton_LamMoi.setText("Làm mới");
        jXButton_LamMoi.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_LamMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_LamMoiActionPerformed(evt);
            }
        });

        jXButton_Xoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        jXButton_Xoa.setText("Xóa");
        jXButton_Xoa.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_Xoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_XoaActionPerformed(evt);
            }
        });

        jXButton_Sua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit.png"))); // NOI18N
        jXButton_Sua.setText("Sửa");
        jXButton_Sua.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXButton_Sua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_SuaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel_NenLayout = new javax.swing.GroupLayout(jXPanel_Nen);
        jXPanel_Nen.setLayout(jXPanel_NenLayout);
        jXPanel_NenLayout.setHorizontalGroup(
            jXPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel_NenLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jXButton_Them, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(jXButton_Sua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jXButton_Xoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(jXButton_LamMoi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXButton_Thoat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64))
            .addGroup(jXPanel_NenLayout.createSequentialGroup()
                .addGroup(jXPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel_NenLayout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addGroup(jXPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jXPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 616, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jXPanel_NenLayout.createSequentialGroup()
                        .addGap(253, 253, 253)
                        .addComponent(jXLabel_TieuDe, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        jXPanel_NenLayout.setVerticalGroup(
            jXPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel_NenLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jXLabel_TieuDe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jXPanel_NenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jXButton_Sua, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE)
                    .addComponent(jXButton_Xoa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXButton_LamMoi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXButton_Thoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jXButton_Them, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jXPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(jXPanel_Nen, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jXButton_ThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_ThoatActionPerformed
        if (isThem){
            jXButton_Them.setEnabled(true);
            jXButton_Sua.setEnabled(true);
            jXButton_Xoa.setEnabled(true);
            jXButton_LamMoi.setText("Làm mới");
            isThem = false;
            jXTextField_TenTaiKhoan.setEnabled(false);
            jPasswordField_MatKhau.setEnabled(false);
            return;
        }
        if (isSua){
            jXButton_Them.setEnabled(true);
            jXButton_Sua.setEnabled(true);
            jXButton_Xoa.setEnabled(true);
            jXButton_LamMoi.setText("Làm mới");
            isSua = false;
            jXTextField_TenTaiKhoan.setEnabled(false);
            jPasswordField_MatKhau.setEnabled(false);
            return;
        }
        if (isXoa){
            jXButton_Them.setEnabled(true);
            jXButton_Sua.setEnabled(true);
            jXButton_Xoa.setEnabled(true);
            jXButton_LamMoi.setText("Làm mới");
            isXoa = false;
            jXTextField_TenTaiKhoan.setEnabled(false);
            jPasswordField_MatKhau.setEnabled(false);
            return;
        }
        this.dispose();
    }//GEN-LAST:event_jXButton_ThoatActionPerformed

    private void jXButton_ThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_ThemActionPerformed
        jXButton_Them.setEnabled(false);
        jXButton_Sua.setEnabled(false);
        jXButton_Xoa.setEnabled(false);
        jXButton_LamMoi.setText("Thêm");        
        isThem = true;
        
        jXTextField_TenTaiKhoan.setEnabled(true);
        jPasswordField_MatKhau.setEnabled(true);
        jComboBox_MaTaiKhoan.setEnabled(true);
        jXTextField_TenTaiKhoan.setText(null);
        jPasswordField_MatKhau.setText(null);
        
    }//GEN-LAST:event_jXButton_ThemActionPerformed

    private void jXButton_LamMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_LamMoiActionPerformed
        if (isThem){
            ThemTaiKhoan();
            jXButton_ThemActionPerformed(evt);
            return;
        }
        
        if (isSua){
            if(jXTextField_TenTaiKhoan.getText().equals("")){
                JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn tài khoản chỉnh sửa.", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            SuaTaiKhoan();
            jXButton_SuaActionPerformed(evt);
            return;
        }
        
        
        if (isXoa){
            if(jXTextField_TenTaiKhoan.getText().equals("")){
                JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn tài khoản cần xóa.", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            XoaTaiKhoan();
            jXButton_XoaActionPerformed(evt);
            return;
        }
        
        jXButton_Them.setEnabled(true);
        jXTextField_TenTaiKhoan.setEnabled(true);
        jPasswordField_MatKhau.setEnabled(true);
        jComboBox_MaTaiKhoan.setEnabled(true);
        jXTextField_TenTaiKhoan.setText(null);
        jPasswordField_MatKhau.setText(null);
        
        
    }//GEN-LAST:event_jXButton_LamMoiActionPerformed

    private void jPasswordField_MatKhauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField_MatKhauActionPerformed
        if(isThem){
            ThemTaiKhoan();
            jXButton_ThemActionPerformed(evt);
            return;
        }
        if (isSua){
            if(jXTextField_TenTaiKhoan.getText().equals("")){
                JOptionPane.showMessageDialog(rootPane, "Vui lòng chọn tài khoản chỉnh sửa.", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            SuaTaiKhoan();
            jXButton_SuaActionPerformed(evt);
            return;
        }
    }//GEN-LAST:event_jPasswordField_MatKhauActionPerformed

    private void jXButton_XoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_XoaActionPerformed
        jXButton_Them.setEnabled(false);
        jXButton_Sua.setEnabled(false);
        jXButton_LamMoi.setText("Thực hiện");
        jXButton_Xoa.setEnabled(false);
        isXoa = true;
        
        
        jXTextField_TenTaiKhoan.setEnabled(false); //Khong cho sua ten
        jPasswordField_MatKhau.setEnabled(true);
        jComboBox_MaTaiKhoan.setEnabled(true);
        jXTextField_TenTaiKhoan.setText(null);
        jPasswordField_MatKhau.setText(null);
    }//GEN-LAST:event_jXButton_XoaActionPerformed

    private void jXButton_SuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_SuaActionPerformed
        jXButton_Them.setEnabled(false);
        jXButton_Xoa.setEnabled(false);
        jXButton_LamMoi.setText("Cập nhật");
        jXButton_Sua.setEnabled(false);
        isSua = true;
        
        
        jXTextField_TenTaiKhoan.setEnabled(false); //Khong cho sua ten
        jPasswordField_MatKhau.setEnabled(true);
        jComboBox_MaTaiKhoan.setEnabled(true);
        jXTextField_TenTaiKhoan.setText(null);
        jPasswordField_MatKhau.setText(null);
    }//GEN-LAST:event_jXButton_SuaActionPerformed

    private void jXTable_TaiKhoanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable_TaiKhoanMouseClicked
        int row = jXTable_TaiKhoan.getSelectedRow();

        jXTextField_TenTaiKhoan.setText("" + jXTable_TaiKhoan.getValueAt(row, 1));
        
    }//GEN-LAST:event_jXTable_TaiKhoanMouseClicked

    private void jXTable_TaiKhoanMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jXTable_TaiKhoanMouseMoved
      int row1 = jXTable_TaiKhoan.rowAtPoint(evt.getPoint());  
      if (row1 > -1)  
      {  
         jXTable_TaiKhoan.clearSelection();  
         jXTable_TaiKhoan.setRowSelectionInterval(row1, row1);  
      }  
//      else  
//      {  
//         jXTable_TaiKhoan.setSelectionBackground(Color.blue);  
//      }
      
      
    }//GEN-LAST:event_jXTable_TaiKhoanMouseMoved

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox_MaTaiKhoan;
    private javax.swing.JPasswordField jPasswordField_MatKhau;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.swingx.JXButton jXButton_LamMoi;
    private org.jdesktop.swingx.JXButton jXButton_Sua;
    private org.jdesktop.swingx.JXButton jXButton_Them;
    private org.jdesktop.swingx.JXButton jXButton_Thoat;
    private org.jdesktop.swingx.JXButton jXButton_Xoa;
    private org.jdesktop.swingx.JXLabel jXLabel_MaTaiKhoan;
    private org.jdesktop.swingx.JXLabel jXLabel_MatKhau;
    private org.jdesktop.swingx.JXLabel jXLabel_TenTaiKhoan;
    private org.jdesktop.swingx.JXLabel jXLabel_TieuDe;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel_Nen;
    private org.jdesktop.swingx.JXTable jXTable_TaiKhoan;
    private org.jdesktop.swingx.JXTextField jXTextField_TenTaiKhoan;
    // End of variables declaration//GEN-END:variables
}
